﻿using System;
using MessagePack.Formatters;
using UnityEngine;

namespace MessagePack.Unity
{
	// Token: 0x02000134 RID: 308
	public sealed class BoundsFormatter : IMessagePackFormatter<Bounds>
	{
		// Token: 0x06000496 RID: 1174 RVA: 0x00014184 File Offset: 0x00012584
		public int Serialize(ref byte[] bytes, int offset, Bounds value, IFormatterResolver formatterResolver)
		{
			int num = offset;
			offset += MessagePackBinary.WriteFixedArrayHeaderUnsafe(ref bytes, offset, 2);
			offset += formatterResolver.GetFormatterWithVerify<Vector3>().Serialize(ref bytes, offset, value.center, formatterResolver);
			offset += formatterResolver.GetFormatterWithVerify<Vector3>().Serialize(ref bytes, offset, value.size, formatterResolver);
			return offset - num;
		}

		// Token: 0x06000497 RID: 1175 RVA: 0x000141D8 File Offset: 0x000125D8
		public Bounds Deserialize(byte[] bytes, int offset, IFormatterResolver formatterResolver, out int readSize)
		{
			if (MessagePackBinary.IsNil(bytes, offset))
			{
				throw new InvalidOperationException("typecode is null, struct not supported");
			}
			int num = offset;
			int num2 = MessagePackBinary.ReadArrayHeader(bytes, offset, out readSize);
			offset += readSize;
			Vector3 center = default(Vector3);
			Vector3 size = default(Vector3);
			for (int i = 0; i < num2; i++)
			{
				int num3 = i;
				if (num3 != 0)
				{
					if (num3 != 1)
					{
						readSize = MessagePackBinary.ReadNextBlock(bytes, offset);
					}
					else
					{
						size = formatterResolver.GetFormatterWithVerify<Vector3>().Deserialize(bytes, offset, formatterResolver, out readSize);
					}
				}
				else
				{
					center = formatterResolver.GetFormatterWithVerify<Vector3>().Deserialize(bytes, offset, formatterResolver, out readSize);
				}
				offset += readSize;
			}
			readSize = offset - num;
			Bounds result = new Bounds(center, size);
			return result;
		}
	}
}
